import {
    SET_CATEGORY_INFO,
    SET_MENULIST,
    SET_BRAND_INFO,
    SET_CARNOUSEL_PIC,
    SHOW_SUB,
    HIDDEN_SUB,
} from './actionsType'
import { getAllCategory } from '@/api/category'
import { getBrandData, getBannerList } from '@/api/home'


export default {
    // 获取首页头部分类数据
    async [SET_CATEGORY_INFO]({ commit }, props) {
        const { result } = await getAllCategory()
        // 给一级分类加上一个控制二级分类显示隐藏的数据open
        result.forEach(rItem => {
            rItem.open = false
        })
        commit(SET_CATEGORY_INFO, result)
        commit(SET_MENULIST)
    },
    // 获取品牌数据
    async [SET_BRAND_INFO]({ commit }, props) {
        const { result } = await getBrandData()
        commit(SET_BRAND_INFO, result)
    },
    // 获取轮播图数据
    async [SET_CARNOUSEL_PIC]({ commit }, props) {
        const { result } = await getBannerList()
        commit(SET_CARNOUSEL_PIC, result)
    },
    // 展示二级分类
    [SHOW_SUB]({ commit }, id) {
        commit(SHOW_SUB, id)
    },
    // 隐藏二级分类
    [HIDDEN_SUB]({ commit }, id) {
        commit(HIDDEN_SUB, id)
    }
}